package com.example.im.manager

import android.app.Activity
import androidx.appcompat.app.AppCompatActivity
import com.example.im.utils.LogUtils

import java.util.ArrayList

/**
 * Created by linlimin on 2019/5/11.
 */
object ActivityCollector {

    var activities: MutableList<Activity> = ArrayList()

    /**
     * 添加活动activity
     *
     * @param activity 活动
     */
    fun addActivity(activity: Activity) {
        activities.add(activity)
    }

    /**
     * 删除指定活动activity
     *
     * @param activity 活动
     */
    fun removeActivity(activity: Activity) {
        activities.remove(activity)
    }

    /**
     * 删除所有活动activity
     */
    fun finishAll() {
        for (activity in activities) {
            if (!activity.isFinishing) {
                activity.finish()
            }
        }
        activities.clear()
    }

    fun finish(cls: Class<*>) {
        activities.forEach {
            if (it.javaClass == cls) {
                it.finish()
            }
        }
    }
}
